package com.baymax.test.scene.demo

import android.content.Context
import android.content.res.Resources.NotFoundException
import android.os.Bundle
import android.os.HandlerThread
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addText
import com.baymax.test.scene.newScrollContainer
import io.reactivex.Observable
import kotlin.properties.Delegates

/**
 * @title:       标题
 * @project:     TestScene
 * @package:     com.baymax.test.scene.demo
 * @class:       RxjavaScene
 * @description:
 * <p>
 * 类描述
 * </p>
 *
 * @version:   1.0
 * @createDate:   2022/6/15 22:01
 * @Copyright (C) 2022 YSTEN
 * @author:       xuyujian
 */
class ResourceScene : BaseScene() {

    fun Context.getPxResourceId(px: Int): Int {
        val id = this.resources.getIdentifier("px$px", "dimen", this.packageName)
        var dimensionPixelSize = 46
        try {
            dimensionPixelSize = this.resources.getDimensionPixelSize(id)
        } catch (e: NotFoundException) {
            e.printStackTrace()
        }
        println("getPxResourceId $id ,$px -> $dimensionPixelSize")
        return dimensionPixelSize
    }

    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return p1.newScrollContainer {
            val c = p1.context
            var t: TextView = addText("")
            HandlerThread("log").threadId
            var size by Delegates.observable(0) { p, o, n ->
                val txtS = c.getPxResourceId(n)
                t.textSize = txtS.toFloat()
                t.text = "px$n($txtS)"
            }
            size = 20
            addButton("++") {
                size += 1
            }
            addButton("--") {
                size -= 1
            }


        }
    }
}